package com.first.nell.components.form

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.RelativeLayout
import androidx.fragment.app.FragmentManager
import com.first.nell.R
import com.first.nell.base.BaseFormAction
import com.first.nell.data.RevObjInfoPageFieldConfig
import com.first.nell.databinding.ViewFirstNellFormSelfieBinding

class SelfieForm : RelativeLayout,
    com.first.nell.components.form.BaseFormAction, BaseFormAction {

    lateinit var mFirstNellViewFirstNellBinding: ViewFirstNellFormSelfieBinding
    private lateinit var vFirstNellRootFirstNellView: View

    private var mFirstNellSupportFirstNellFragmentFirstNellManager: FragmentManager? = null
    private var mFirstNellFormFirstNellConfig: RevObjInfoPageFieldConfig? = null
    private var mFirstNellOnFirstNellStateFirstNellChangedFirstNellListener: (Int, String) -> Unit =
        { action, content -> }

    private var mFirstNellOnFirstNellActionFirstNellClickFirstNellListener: (Int) -> Unit = {}

    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : this(
        context,
        attrs,
        defStyleAttr,
        0
    )

    @SuppressLint("Recycle")
    constructor(
        context: Context?,
        attrs: AttributeSet?,
        defStyleAttr: Int,
        defStyleRes: Int,
    ) : super(
        context,
        attrs,
        defStyleAttr,
        defStyleRes
    ) {
        context?.let {
            vFirstNellRootFirstNellView = View.inflate(it, R.layout.view_first_nell_form_selfie, this)
            mFirstNellViewFirstNellBinding = ViewFirstNellFormSelfieBinding.bind(vFirstNellRootFirstNellView)
            initFirstNellSubviews()
        }
    }

    override fun initFirstNellSubviews() {
        try {
            mFirstNellViewFirstNellBinding.imageFormSelfieHint.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(0)
            }

        } catch (e: java.lang.Exception) {
            e.printStackTrace()
        }
    }

    override fun isFirstNellFormFirstNellCompleted(): Boolean {
        return true
    }

    override fun isFirstNellFormFirstNellCompletedFirstNellSilent(): Boolean {
        return true
    }

    override fun setFirstNellOnFirstNellStateFirstNellChangedFirstNellListener(listener: (Int, String) -> Unit) {
        mFirstNellOnFirstNellStateFirstNellChangedFirstNellListener = listener
    }

    override fun setFirstNellTitle(title: String) {
        mFirstNellViewFirstNellBinding.textFormSelfieTitle.text = (title)
    }

    override fun setFirstNellHint(hint: String) {
        mFirstNellViewFirstNellBinding.textFormSelfieTip.text = (hint)
    }

    override fun setFirstNellFormFirstNellConfig(item: RevObjInfoPageFieldConfig) {
        mFirstNellFormFirstNellConfig = item
        setFirstNellTitle(item.title.toString())
        setFirstNellHint(item.hint.toString())
        tag = item.paramName
        if (item.needCheckComplete == true) {
            isFirstNellFormFirstNellCompleted()
        }
    }

    override fun setFirstNellFragmentFirstNellManager(manager: FragmentManager) {
        mFirstNellSupportFirstNellFragmentFirstNellManager = manager
    }

    override fun setFirstNellOnFirstNellActionFirstNellClickFirstNellListener(listener: (Int) -> Unit) {
        mFirstNellOnFirstNellActionFirstNellClickFirstNellListener = listener
    }

    override fun setFirstNellDetail(detail: String) {

    }

    override fun setFirstNellContent(content: String) {

    }

    override fun setFirstNellDetailFirstNellColor(detailColor: Int) {

    }

    override fun setFirstNellTitleFirstNellColor(titleColor: Int) {

    }
}